package com.itheima.service.impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.pojo.domain.ClazzOption;
import com.itheima.pojo.domain.GenderOption;
import com.itheima.pojo.domain.JobOption;
import com.itheima.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Slf4j
@Service
public class ReportServiceImpl implements ReportService {


    @Autowired
    private ReportMapper reportMapper;

    @Override
    public JobOption empPositionStatistics() {

        //职位统计
        List<Map<String,Long>> mapList = reportMapper.empPositionStatistics();
        //职位名称
        List<String> pos = mapList.stream().map(map -> String.valueOf(map.get("pos"))).toList();
        //职位数量
        List<Long> count = mapList.stream().map(map -> map.get("total")).toList();
        //封装数据
        return new JobOption(pos,count) ;
    }

    @Override
    public List<GenderOption> empGenderStatistics() {

        List<GenderOption> mapList = reportMapper.empGenderStatistics();


        return mapList ;
    }

    @Override
    public List<GenderOption> empEducationStatistics() {

        List<GenderOption> mapList = reportMapper.empEducationStatistics();

        return mapList;
    }

    @Override
    public ClazzOption empCountStatistics() {
        List<Map<String,Long>> mapList  = reportMapper.empCountStatistics();
        List<String> name = mapList.stream().map(nv -> String.valueOf(nv.get("name")) ).collect(Collectors.toList());
        List<Long> value = mapList.stream().map(nv -> nv.get("value")).collect(Collectors.toList());

        return new ClazzOption(name,value);
    }
}
